package com.jfl.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;

/**
 * 时间工具类
 * 
 * @author 赵炎
 * @version [V1.00, 2018年12月31日]
 * @since V1.00
 */
public class DateUtil
{
    public static final String YYYYMMDD = "yyyyMMdd";
    
    public static final String YYYY_MM_DD = "yyyy-MM-dd";
    
    public static final String YYYY_MM_DDHHMMSS = "yyyy-MM-dd HH:mm:ss";
    
    
    /**
     * 获取当前时间
     * 
     * @return
     */
    public static Date getCurrentDate()
    {
        Calendar calendar = Calendar.getInstance();
        return calendar.getTime();
    }
    
    /**
     * 格式化时间
     * 
     * @param date
     * @param pattern
     * @return
     */
    public static String format(Date date, String pattern)
    {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }
    
    /**
     * 格式化时间 默认“yyyy-MM-dd HH:mm:ss”
     * 
     * @param date
     * @return
     */
    public static String format(Date date)
    {
        SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DDHHMMSS);
        return sdf.format(date);
    }
    
    /**
     * 转换时间异常
     * 
     * @param date
     * @param pattern
     * @return
     */
    public static Date parse(String date, String pattern)
    {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        try
        {
            sdf.parse(date);
        }
        catch (ParseException e)
        {
            return null;
        }
        return null;
    }
    public static void main(String[] args)
    {
        System.out.println(DateUtils.addMilliseconds(DateUtil.getCurrentDate(), 60000));
    }
}
